package util;

import java.util.StringTokenizer;

public class SequencePredeterminee implements Sequence {

	public final static String NOMBRE_SEQUENCE_PROPERTY_NAME = "sim.sequence.predeterminee";
	private int[] sequence;
	private static int actualIndex = 0;

	public SequencePredeterminee() {
		String stringSequence = SimProperties.getInstance().getStringProperty(
				NOMBRE_SEQUENCE_PROPERTY_NAME);
		StringTokenizer tokenizer = new StringTokenizer(stringSequence);
		int count = tokenizer.countTokens();
		sequence = new int[count];

		for (int i = 0; i < count; i++) {
			sequence[i] = Integer.parseInt(tokenizer.nextToken());
		}
	}

	@Override
	public int nextNumber() {
		int retVal;
		retVal = sequence[actualIndex];
		
		// On recommence la séquence lorsqu'on a terminé.
		if (++actualIndex >= sequence.length) {
			actualIndex = 0;
		}
		return retVal;
	}
	
	public static void reset()
	{
		actualIndex = 0;
	}

}
